#!/bin/bash

# 颜色输出函数
f_echo(){
    echo -e "\033[$1m$2\033[0m"
}

# 显示选项并获取用户输入
echo "请选择要更新的目录："
echo "1) common-env"
echo "2) 200f"
echo "3) 101"

read -p "请输入数字 (1 或 2或3)后按回车键继续" choice

case "$choice" in
    1)
        TARGET="common-env"
        SCRIPT="git_upload_to_svn_common.sh"
        DEFAULT_SUB_DIR="02-非信创/00-common-env"
        LOCAL_REPO="/data/transfer/local_git_common_env_dir"
        ;;
    2)
        TARGET="200f"
        SCRIPT="git_upload_to_svn.sh"
        DEFAULT_SUB_DIR="02-非信创/01-dlmu-station/01-dlmu200f"
        LOCAL_REPO="/data/transfer/local_git_dir"
        ;;
	3)
        TARGET="101"
        SCRIPT="git_upload_to_svn.sh"
        DEFAULT_SUB_DIR="02-非信创/01-dlmu-station/02-dlmu101"
        LOCAL_REPO="/data/transfer/local_git_dir"
        ;;
    *)
        f_echo 31 "❌ 输入无效，请输入 1 或 2 或 3"
        exit 1
        ;;
esac

# 输出当前选择安装的目录
f_echo 32 "✅ 当前选择安装的目录是：$TARGET"

# 检查脚本是否存在
if [ ! -f "$SCRIPT" ]; then
    f_echo 31 "找不到脚本文件: $SCRIPT"
    exit 1
fi

# 设置变量
GIT_URL="http://192.168.2.200:8001/engineer-script/smart-scripts.git"
# 要拉取的git的子目录
SUB_DIR="$DEFAULT_SUB_DIR"
BRANCH_NAME="scripts-dev"
GIT_USER_NAME="13674987759@163.com"
GIT_TOKEN="zs123456"

# 显示确认信息
f_echo 36 "🔧 即将执行上传脚本，使用以下参数："
echo "Git 地址: $GIT_URL"
echo "拉取的git的子目录: $SUB_DIR"
echo "分支名: $BRANCH_NAME"
echo "本地仓库路径: $LOCAL_REPO"
echo "参数已准备完毕，开始执行脚本"

# 执行对应的脚本
f_echo 33 "正在使用脚本: $SCRIPT"

sh git_upload_to_svn_common.sh
sh "$SCRIPT" "$GIT_URL" "$GIT_USER_NAME" "$GIT_TOKEN" "$SUB_DIR" "$BRANCH_NAME" "$LOCAL_REPO"